package com.tanhua.server.controller;

import com.tanhua.model.mongo.Answer;
import com.tanhua.model.vo.QuestionnaireVO;
import com.tanhua.model.vo.ReportVo;
import com.tanhua.server.service.TestSoulService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/testSoul")
public class TestSoulController {

    @Autowired
    private TestSoulService testSoulService;

    /**
     * 测灵魂-问卷列表（学生实战）
     * @return
     */
    @GetMapping
    public ResponseEntity getQuestionnaire() {
        List<QuestionnaireVO> vos = testSoulService.getQuestionnaire();
        return ResponseEntity.ok(vos);
    }

    /**
     * 测灵魂-提交问卷（学生实战）
     * @return
     */
    @PostMapping
    public ResponseEntity commitQuestionnaire(@RequestBody Map<String, List<Answer>> answers) {
        String reportId = testSoulService.commitQuestionnaire(answers);
        return ResponseEntity.ok(reportId);
    }

    @GetMapping("/report/{reportId}")
    public ResponseEntity getReport(@PathVariable String reportId) {
        ReportVo vo = testSoulService.getReport(reportId);
        return ResponseEntity.ok(vo);
    }
}
